#ifndef _WX_WINPARS_H_
#define _WX_WINPARS_H_

#include "wx/defs.h"
#include "wx/module.h"
#include "wx/font.h"
#include "wx/html/htmlpars.h"
#include "wx/html/htmlcell.h"
#include "wx/encconv.h"

class wxHtmlWindow;
class wxHtmlWindowInterface;
class wxHtmlWinParser;
class wxHtmlWinTagHandler;
class wxHtmlTagsModule;
struct wxHtmlWinParser_TextParsingState;

class wxHtmlWinParser : public wxHtmlParser {
    DECLARE_ABSTRACT_CLASS( wxHtmlWinParser )
    friend class wxHtmlWindow;

  public:
    wxHtmlWinParser( wxHtmlWindowInterface *wndIface = NULL );
    virtual ~wxHtmlWinParser();
    virtual void InitParser( const wxString& source );
    virtual void DoneParser();
    virtual wxObject* GetProduct();
    virtual wxFSFile *OpenURL( wxHtmlURLType type, const wxString& url ) const;
    virtual void SetDC( wxDC *dc, double pixel_scale = 1.0 ) { m_DC = dc; m_PixelScale = pixel_scale; }

    wxDC *GetDC() {return m_DC;}
    double GetPixelScale() {return m_PixelScale;}
    int GetCharHeight() const {return m_CharHeight;}
    int GetCharWidth() const {return m_CharWidth;}
    wxHtmlWindowInterface *GetWindowInterface() {return m_windowInterface;}
    wxDEPRECATED( wxHtmlWindow *GetWindow() );
    void SetFonts( const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL );
    void SetStandardFonts( int size = -1,const wxString& normal_face = wxEmptyString,
                           const wxString& fixed_face = wxEmptyString );
    static void AddModule( wxHtmlTagsModule *module );
    static void RemoveModule( wxHtmlTagsModule *module );
    wxHtmlContainerCell *GetContainer() const {return m_Container;}
    wxHtmlContainerCell *OpenContainer();
    wxHtmlContainerCell *SetContainer( wxHtmlContainerCell *c );
    wxHtmlContainerCell *CloseContainer();
    int GetFontSize() const {return m_FontSize;}
    void SetFontSize( int s );
    int GetFontBold() const {return m_FontBold;}
    void SetFontBold( int x ) {m_FontBold = x;}
    int GetFontItalic() const {return m_FontItalic;}
    void SetFontItalic( int x ) {m_FontItalic = x;}
    int GetFontUnderlined() const {return m_FontUnderlined;}
    void SetFontUnderlined( int x ) {m_FontUnderlined = x;}
    int GetFontFixed() const {return m_FontFixed;}
    void SetFontFixed( int x ) {m_FontFixed = x;}
    wxString GetFontFace() const {return GetFontFixed() ? m_FontFaceFixed : m_FontFaceNormal;}
    void SetFontFace( const wxString& face );
    int GetAlign() const {return m_Align;}
    void SetAlign( int a ) {m_Align = a;}
    wxHtmlScriptMode GetScriptMode() const { return m_ScriptMode; }
    void SetScriptMode( wxHtmlScriptMode mode ) { m_ScriptMode = mode; }
    long GetScriptBaseline() const { return m_ScriptBaseline; }
    void SetScriptBaseline( long base ) { m_ScriptBaseline = base; }
    const wxColour& GetLinkColor() const { return m_LinkColor; }
    void SetLinkColor( const wxColour& clr ) { m_LinkColor = clr; }
    const wxColour& GetActualColor() const { return m_ActualColor; }
    void SetActualColor( const wxColour& clr ) { m_ActualColor = clr ;}
    const wxHtmlLinkInfo& GetLink() const { return m_Link; }
    void SetLink( const wxHtmlLinkInfo& link );
    void ApplyStateToCell( wxHtmlCell *cell );
    virtual wxFont* CreateCurrentFont();
    enum WhitespaceMode {
      Whitespace_Normal,
      Whitespace_Pre
    };


    void SetWhitespaceMode( WhitespaceMode mode );
    WhitespaceMode GetWhitespaceMode() const;

  protected:
    virtual void AddText( const wxChar* txt );

  private:
    void FlushWordBuf( wxChar *temp, int& templen, wxChar nbsp );
    void AddWord( wxHtmlWordCell *c );
    void AddWord( const wxString& word );
    void AddPreBlock( const wxString& text );

    bool m_tmpLastWasSpace;
    wxChar *m_tmpStrBuf;
    size_t  m_tmpStrBufSize;

    wxHtmlWindowInterface *m_windowInterface;

    double m_PixelScale;
    wxDC *m_DC;

    static wxList m_Modules;



    wxHtmlContainerCell *m_Container;


    int m_FontBold, m_FontItalic, m_FontUnderlined, m_FontFixed;
    int m_FontSize; /* -2 to +4,  0 is default */
    wxColour m_LinkColor;
    wxColour m_ActualColor;

    wxHtmlLinkInfo m_Link;

    bool m_UseLink;

    long m_CharHeight, m_CharWidth;

    int m_Align;

    wxHtmlScriptMode m_ScriptMode;

    long m_ScriptBaseline;


    wxFont* m_FontsTable[2][2][2][2][7];
    wxString m_FontsFacesTable[2][2][2][2][7];
    int m_FontsSizes[7];
    wxString m_FontFaceFixed, m_FontFaceNormal;
    wxHtmlWinParser_TextParsingState *m_textParsingState;

    DECLARE_NO_COPY_CLASS( wxHtmlWinParser )
};

class wxHtmlWinTagHandler : public wxHtmlTagHandler {
    DECLARE_ABSTRACT_CLASS( wxHtmlWinTagHandler )

  public:
    wxHtmlWinTagHandler() : wxHtmlTagHandler() {}

    virtual void SetParser( wxHtmlParser *parser ) {wxHtmlTagHandler::SetParser( parser ); m_WParser = ( wxHtmlWinParser* ) parser;}

  protected:
    wxHtmlWinParser *m_WParser;

    DECLARE_NO_COPY_CLASS( wxHtmlWinTagHandler )
};

class wxHtmlTagsModule : public wxModule {
    DECLARE_DYNAMIC_CLASS( wxHtmlTagsModule )
  public:
    wxHtmlTagsModule() : wxModule() {}
    virtual bool OnInit();
    virtual void OnExit();
    virtual void FillHandlersTable( wxHtmlWinParser * ( parser ) ) { }
};

#endif
